package StudyCode.summary.myfile;

import java.io.File;
import java.io.FileInputStream;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class FileContentEqual {
	public static void main(String[] argv) {
		File file1 = new File("E:\\迅雷下载\\test1.txt");
		File file2 = new File("E:\\迅雷下载\\test1.txt");
		System.out.println(file1 + " 等于 " + file2 + " 吗？ " + fileEquals(file1, file2));
	}

	private static boolean fileEquals(File file1, File file2) {
		try {
			FileInputStream f1 = new FileInputStream(file1);
			FileInputStream f2 = new FileInputStream(file2);
			byte[] b1 = new byte[(int) file1.length()];
			byte[] b2 = new byte[(int) file2.length()];
			f1.read(b1);
			f2.read(b2);
			for (int j = 0; j < b1.length; j++) {
				if (b1[j] != b2[j])
					return false;
			}
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
}
